package org.csu.leiyun.spring.demo.ioc.test;

import org.csu.leiyun.spring.demo.ioc.domain.Account;
import org.csu.leiyun.spring.demo.ioc.persistence.AccountDAO;
import org.csu.leiyun.spring.demo.ioc.persistence.AccountDAOimpl;
import org.csu.leiyun.spring.demo.ioc.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo {
    @Autowired
    private AccountService accountService;//联合测试注解引用

    @Test
    public void test(){
        //AccountDAO accountDAO = new AccountDAOimpl();
        //使用Spring Ioc容器来获取对象的方式
        //ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
//        AccountDAO accountDAO = (AccountDAO)context.getBean("accountDAO");
//        accountDAO.insert();
//        accountDAO.delete();
//        accountDAO.find();
//        accountDAO.update();

//        Account account=(Account)context.getBean("account");
//        System.out.println(account.getUsername()+","+account.getPassword()+","+account.getAge());
//
//        AccountService accountService=(AccountService)context.getBean("accountService");
//        accountService.login();

        accountService.login();
    }
}
